﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Way.Bus.Controllers;
using Way.Bus.WMS.Model;
using Way.Contract.MVC;
using Way.Contract.Data.ControllerData;
using Way.EAP.DataAccess.Entity;
using Way.EAP.DataAccess.Regulation;

namespace Way.Bus.WMS.Controllers
{
    public class SFLoanOrderController : LoanOrderController
    {

        #region 初始化数据方法
        protected override void OnInitViewChildItem(Way.Contract.Data.ModelData data, Way.Contract.Data.ItemData item)
        {
            if (data.name.EndsWith("LoanOrder"))
           {
                switch (item.field.ToLower())
                {
                    case "rowindex":
                    case "loanorderno":
                    case "createdby":
                    case "creationdate":
                    case "remark":
                        item.visible = true;
                        break;
                    default:
                        item.visible = false;
                        break;
                }
            }
            if (data.name.EndsWith("LoanOrderMaterials"))
            {
                switch (item.field.ToLower())
                {
                    case "warehousename":
                    case "materialcode":
                    case "num":
                    case "loaner":
                        item.visible = true;
                        break;
                    default:
                        item.visible = false;
                        break;
                }
            }
            if (data.name.EndsWith("StockOutNoticeMaterials"))
                data.visible = false;
        }
        #endregion
        protected override void OnForeignLoading(IModel model, loadItem item)
        {
            if (this.fdata.filedname == "WAREHOUSENAME")
            {
                SQLWhere tempSql = new SQLWhere();
                tempSql.ColumnName = "Acc_WMS_WareHouse.WHTYPE";
                tempSql.Relation = "and";
                tempSql.Type = "int";
                tempSql.Value = "0";
                List<SQLWhere> tempList = new List<SQLWhere>();
                tempList.Add(tempSql);
                item.whereList = tempList.ToArray();
            }
            if (this.fdata.filedname == "MATERIALCODE")
            {
                SQLWhere tempSql = new SQLWhere();
                tempSql.ColumnName = "Acc_Bus_BusinessCommodity.ID";
                tempSql.Symbol = "in";
                tempSql.Value = "(select Code from Acc_WMS_InfoMaterials)";
                List<SQLWhere> tempList = new List<SQLWhere>();
                tempList.Add(tempSql);
                item.whereList = tempList.ToArray();
            }
            base.OnForeignLoading(model, item);
        }
    }
}
